package com.kehutong.payfees.service.receipt;

import com.kehutong.payfees.entity.receipt.ReceiptTemplate;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.logger.Logger;
import org.coraframework.logger.LoggerFactory;
import org.coraframework.orm.Pool;
import org.coraframework.orm.jdbc.JdbcSession;
import org.coraframework.orm.jdbc.Page;
import org.coraframework.orm.jdbc.execute.entity.FindPage;

import java.util.List;

/**
 * @program: kht
 * @description: 模板管理
 * @author: joneron
 * @create: 2021/5/29
 **/
public class ReceiptTempServiceImpl {

    private static final Logger logger = LoggerFactory.getLogger(ReceiptTempServiceImpl.class);

    @Inject
    private JdbcSession jdbcSession;

    public Page<ReceiptTemplate> findPage(JSONObject jsonObject) {

        FindPage<ReceiptTemplate> find = jdbcSession.findPage(ReceiptTemplate.class)
                .eq("deleted", false)
                .order("createTime", "desc");

        find.page(jsonObject);

        return find.exe();
    }

    public List<ReceiptTemplate> findList(JSONObject jsonObject) {

        List<ReceiptTemplate> receiptList = jdbcSession.findArray(ReceiptTemplate.class)
                .eq("deleted", false)
                .eq("status",true)
                .exe();

        return receiptList;
    }

    public Integer save(ReceiptTemplate entity) {

        return jdbcSession.insert(entity);
    }

    public Integer update(ReceiptTemplate entity) {
        return jdbcSession.updateById(entity);
    }

    public Integer deleteById(String id) {
        ReceiptTemplate result = Pool.get(ReceiptTemplate.class, id);
        if (result != null) {
            result.setDeleted(true);
            jdbcSession.updateById(result);
        }
        return 1;
    }

    public ReceiptTemplate findById(String id){

        return jdbcSession.findById(ReceiptTemplate.class,id);
    }
}
